<template>
  <div class="header">
    <el-row :gutter="20">
      <el-col :span="4">
        <div class="grid-content">logo</div>
      </el-col>
      <div class="big-header">
        <el-col :span="5" :offset="6">
          <div class="grid-content">
            <el-input
                    size="small"
                    placeholder="请输入内容"
                    prefix-icon="el-icon-search"
                    v-model="input"
                    clearable>
            </el-input>
          </div>
        </el-col>
        <el-col :span="8" :offset="1">
          <div class="grid-content">
            <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
              <el-menu-item index="1">笔记</el-menu-item>
              <el-menu-item index="2">教程</el-menu-item>
              <el-menu-item index="3" >常用网站</el-menu-item>
              <el-menu-item index="4">关于</el-menu-item>
            </el-menu>
          </div>
        </el-col>
      </div>
      <div class="small-header">
        <el-col :span="16" :offset="0">
          <div class="grid-content">
            <el-input
                    size="small"
                    placeholder="请输入内容"
                    prefix-icon="el-icon-search"
                    v-model="input"
                    clearable>
            </el-input>
          </div>
        </el-col>
        <el-col :span="4">
          <div>
            <div>
              <el-dropdown trigger="click" placement="top" @command="handleSelect">
                <span class="el-dropdown-link">
                  <i class="el-icon-menu menu-btn"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item icon="el-icon-plus" command="1">笔记</el-dropdown-item>
                  <el-dropdown-item icon="el-icon-circle-plus" command="2">教程</el-dropdown-item>
                  <el-dropdown-item icon="el-icon-circle-plus-outline" command="3">常用网站</el-dropdown-item>
                  <el-dropdown-item icon="el-icon-check" command="4">关于</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </div>
        </el-col>
      </div>
    </el-row>
  </div>
</template>

<script>
  export default {
    name: "Header",
    data(){
      return {
        input: '',
        activeIndex: this.$store.state.activeIndex
      }
    },
    methods: {
      handleSelect(key, keyPath) {
        switch (key) {
          case '1':
            if (this.activeIndex !== '1'){
              this.$router.push('/');
            }
            break;
          case '2':
            break;
          case '3':
            if (this.activeIndex !== '3'){
              this.$router.push('/commonwebs');
            }
            break;
          case '4':
            if (this.activeIndex !== '4') {
              this.$router.push('/about');
            }
            break
        }
        this.$store.state.activeIndex = key;
        this.activeIndex = this.$store.state.activeIndex;
        console.log(this.activeIndex)
      },
      handleCommand(command){
        console.log('click on item ' + command);
      }
    }
  }
</script>

<style scoped>
  @media screen and (max-width: 1000px){
    .big-header {
      display: none;
    }
  }

  @media screen and (min-width: 1000px){
    .small-header {
      display: none;
      text-align: right;
    }
  }

  @media screen and (min-width: 700px) and (max-width: 1000px){
    .el-input {
      width: 70%;
      margin-left: 100px;
    }
  }

  .header {
    line-height: 60px;
    color: #333;
    text-align: center;
  }

  .menu-btn {
    font-size: 1.4em;
    vertical-align: middle;
    opacity: .6;
  }

  .menu-btn:hover {
    cursor: pointer;
    opacity: 1;
  }
</style>
